<template>
  <div>
    <page-dialog
      :title="dialogInfo.title"
      v-model:visible="showDialog"
      :width="dialogInfo.width"
      :bt-list="dialogInfo.btList"
    >
      <div class="model-panel">
        <div class="model-panel-title">
          <p>查询配置</p>
        </div>
        <div class="model-panel-body">
          <el-form>
            <el-form-item label="过滤匹配条件：" class="advance-item">
              <el-select
                v-model="queryCategory"
                placeholder="过滤匹配条件"
                filterable
                style="width: 300px"
              >
                <el-option
                  v-for="(item, index) in queryCategoryOption"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              v-for="(row, index) in formInfo"
              :key="index"
              class="advance-item"
            >
              <el-select
                v-model="row.asName"
                placeholder="请选择查询字段"
                filterable
                style="width: 200px; marginright: 5px"
                :filterMethod="filterMethod"
                @change="changeFiled($event, index)"
                @visible-change="visibleChange"
              >
                <el-option
                  v-for="(item, i) in newFiledList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
              <select-model
                :key="row.queryType"
                v-model:modelValue="row.queryType"
                type-code="determine_term"
                :clearable="false"
                :check-default="true"
                width="150px"
                style="marginright: 5px"
                placeholder="请选择查询条件"
                @change="changeQueryType($event, row, index)"
              />
              <el-input
                v-if="row.componentType === 'input' || !row.componentType"
                v-model="row.value"
                style="width: 300px"
                :clearable="true"
                placeholder="请输入值"
                @input="(e) => (row.value = validSe(e))"
              />
              <el-input-number
                v-if="row.componentType === 'number'"
                v-model="row.value"
                controls-position="right"
                style="width: 300px"
                :clearable="true"
                :precision="systemConfig.qty_show_precision"
                placeholder="请输数字"
                :min="0"
                :max="999999999"
              />
              <el-input-number
                v-if="row.componentType === 'price'"
                v-model="row.value"
                controls-position="right"
                style="width: 300px"
                :precision="systemConfig.price_precision"
                :clearable="true"
                placeholder="请输数字"
                :min="0"
                :max="999999999"
              />
              <el-time-picker
                v-if="row.componentType === 'time'"
                v-model="row.value"
                style="width: 300px"
                placeholder="请选择时间"
              ></el-time-picker>
              <el-date-picker
                v-if="row.componentType === 'date'"
                v-model="row.value"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                type="date"
                style="width: 300px"
                placeholder="请选择日期"
              >
              </el-date-picker>
              <el-date-picker
                v-if="row.componentType === 'dateTime'"
                v-model="row.value"
                format="YYYY-MM-DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="datetime"
                style="width: 300px"
                placeholder="请选择日期时间"
              >
              </el-date-picker>
              <el-date-picker
                v-if="row.componentType === 'month'"
                v-model="row.value"
                type="month"
                format="YYYY-MM"
                value-format="YYYY-MM"
                style="width: 300px"
                placeholder="请选择月份"
              >
              </el-date-picker>
              <select-model
                v-if="row.componentType === 'select-model'"
                :key="row.value"
                v-model:modelValue="row.value"
                :type-code="row.code"
                :clearable="true"
                :clear-type="row.clearType"
                :check-default="false"
                :multiple="row.multiple"
                width="300px"
                placeholder="请选择查询条件"
              />
              <el-input
                v-if="row.componentType === 'select-user'"
                v-model="row.userName"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkUser(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-use-status'"
                v-model="row.userStatusValue"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkUserStatus(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-dept'"
                v-model="row.deptName"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkDept(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-device-type'"
                v-model="row.selectDevice"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkSelectDevice(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-asset-classify-type'"
                v-model="row.selectClassify"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkSelectClassify(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-finance-type'"
                v-model="row.selectFinance"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkSelectFinance(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-product'"
                v-model="row.commonName"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkProduct(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-fiscal-period'"
                v-model="row.fiscalPeriod"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkFiscalPeriod(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-patrol-route'"
                v-model="row.patrolRoute"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkPatrolRoute(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-maintenance'"
                v-model="row.maintenance"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkMaintenance(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-repair-user'"
                v-model="row.name"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkRepairUser(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-maintenance-user'"
                v-model="row.name"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkMaintenanceUser(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-shelf-no'"
                v-model="row.locationNo"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkshelfNo(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <el-input
                v-if="row.componentType === 'select-product-class'"
                v-model="row.name"
                style="width: 300px"
                class="not-mongolia"
                type="input"
                :required="true"
                :disabled="true"
                :placeholder="'请选择' + row.label"
              >
                <template #append>
                  <el-icon @click="checkProductClass(row, index)"
                    ><MoreFilled
                  /></el-icon>
                </template>
              </el-input>
              <slip-select
                v-if="row.componentType === 'slip-select'"
                :ref="'slipSelect' + index"
                v-model:modelValue="row.value"
                style="width: 300px"
                value-key="value"
                :placeholder="'请选择' + row.label"
                :api="row.api"
                :query="row.query"
                :default-value="row.defaultValue"
                :key-field="row.keyField"
                :value-field="row.valueField"
                :clearable="row.clearable === false ? row.clearable : true"
                :filterable="row.filterable === false ? row.filterable : true"
                :disabled="row.disabled"
                :multiple="row.multiple"
                :is-multiple="isMultiple"
                :clear-type="row.clearType"
                :slip-select-request="row.slipSelectRequest"
              />
              <el-date-picker
                v-if="row.componentType === 'datetimerange'"
                v-model="row.timeInfo"
                style="width: 300px"
                format="YYYY-MM-DD HH:mm:ss"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="datetimerange"
                range-separator="至"
                :shortcuts="$fn.pickerOptionsFn()"
                align="right"
                :default-time="[
                  new Date(2000, 1, 1, 0, 0, 0),
                  new Date(2000, 1, 1, 23, 59, 59),
                ]"
                :start-placeholder="row.label + '开始日期'"
                :end-placeholder="row.label + '结束日期'"
                @change="timeChange($event, row)"
              ></el-date-picker>
              <el-date-picker
                v-if="row.componentType === 'daterange'"
                v-model="row.timeInfo"
                style="width: 300px"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                type="daterange"
                range-separator="至"
                :shortcuts="$fn.pickerOptionsFn()"
                align="right"
                :start-placeholder="row.label + '开始日期'"
                :end-placeholder="row.label + '结束日期'"
                @change="timeChange($event, row)"
              ></el-date-picker>
              <i class="check-btn" @click="addRow">
                <el-icon><Plus /></el-icon>
              </i>
              <i
                class="check-btn"
                :class="formInfo.length === 1 ? 'disabled-icon' : ''"
                @click="removeRow(index)"
              >
                <el-icon><Minus /></el-icon>
              </i>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </page-dialog>
    <select-users
      v-if="userInfo.visible"
      v-model:show-dialog="userInfo.visible"
      :api="userInfo.api"
      :save-empty="true"
      :checked-list="
        userInfo.data[userInfo.key].checkBox
          ? userInfo.data[userInfo.key].checkedList
          : []
      "
      :check-box="userInfo.data[userInfo.key].checkBox"
      :highlight-row="userInfo.data[userInfo.key].highlightRow"
      @callback="callBackUser"
    />
    <NewSelectProduct
      v-if="productInfo.visible"
      v-model:show-dialog="productInfo.visible"
      :api="productInfo.row.api"
      :showEditQty="false"
      :query="
        productInfo.row.query
          ? productInfo.row.query.queryMap || productInfo.query
          : productInfo.query
      "
      :queryParams="
        productInfo.row.query ? productInfo.row.query.queryParams || {} : {}
      "
      :tableKey="productInfo.row.tableKey || productInfo.tableKey"
      :allowCoverFilterParams="productInfo.row.allowCoverFilterParams || false"
      :save-empty="true"
      :checked-list="
        productInfo.data[productInfo.key].checkBox
          ? productInfo.data[productInfo.key].checkedList
          : []
      "
      :check-box="productInfo.data[productInfo.key].checkBox"
      :highlight-row="productInfo.data[productInfo.key].highlightRow"
      @callback="selectProduct"
    />
    <select-use-status
      v-if="selectUseStatusInfo.visible"
      v-model:show-dialog="selectUseStatusInfo.visible"
      :api="selectUseStatusInfo.api"
      :save-empty="true"
      :checked-list="
        selectUseStatusInfo.data[selectUseStatusInfo.key].checkBox
          ? selectUseStatusInfo.data[selectUseStatusInfo.key].checkedList
          : []
      "
      :check-box="selectUseStatusInfo.data[selectUseStatusInfo.key].checkBox"
      :highlight-row="
        selectUseStatusInfo.data[selectUseStatusInfo.key].highlightRow
      "
      @callback="callBackUserStatus"
    ></select-use-status>
    <select-dept
      v-if="selectDeptInfo.visible"
      v-model:show-dialog="selectDeptInfo.visible"
      :api="selectDeptInfo.api"
      :save-empty="true"
      :checked-list="
        selectDeptInfo.data[selectDeptInfo.key].checkBox
          ? selectDeptInfo.data[selectDeptInfo.key].checkedList
          : []
      "
      :check-box="selectDeptInfo.data[selectDeptInfo.key].checkBox"
      :highlight-row="selectDeptInfo.data[selectDeptInfo.key].highlightRow"
      :query="selectDeptInfo.row.query"
      @callback="callBackDept"
    ></select-dept>
    <SelectSettingClassification
      v-if="selectDeviceTypeInfo.visible"
      v-model:show-dialog="selectDeviceTypeInfo.visible"
      :api="selectDeviceTypeInfo.api"
      :save-empty="true"
      :checked-list="
        selectDeviceTypeInfo.data[selectDeviceTypeInfo.key].checkBox
          ? selectDeviceTypeInfo.data[selectDeviceTypeInfo.key].checkedList
          : []
      "
      :check-box="selectDeviceTypeInfo.data[selectDeviceTypeInfo.key].checkBox"
      :highlight-row="
        selectDeviceTypeInfo.data[selectDeviceTypeInfo.key].highlightRow
      "
      @callback="callBackselectDeviceType"
    />
    <SelectSettingCategory
      v-if="selectFinanceTypeInfo.visible"
      v-model:show-dialog="selectFinanceTypeInfo.visible"
      :api="selectFinanceTypeInfo.api"
      :save-empty="true"
      :checked-list="
        selectFinanceTypeInfo.data[selectFinanceTypeInfo.key].checkBox
          ? selectFinanceTypeInfo.data[selectFinanceTypeInfo.key].checkedList
          : []
      "
      :check-box="
        selectFinanceTypeInfo.data[selectFinanceTypeInfo.key].checkBox
      "
      :highlight-row="
        selectFinanceTypeInfo.data[selectFinanceTypeInfo.key].highlightRow
      "
      @callback="callBackSelectFinanceType"
    />
    <SelectAssetClassify
      v-if="selectAssetClassifyTypeInfo.visible"
      v-model:show-dialog="selectAssetClassifyTypeInfo.visible"
      :api="selectAssetClassifyTypeInfo.api"
      :save-empty="true"
      :checked-list="
        selectAssetClassifyTypeInfo.data[selectAssetClassifyTypeInfo.key]
          .checkBox
          ? selectAssetClassifyTypeInfo.data[selectAssetClassifyTypeInfo.key]
              .checkedList
          : []
      "
      :check-box="
        selectAssetClassifyTypeInfo.data[selectAssetClassifyTypeInfo.key]
          .checkBox
      "
      :highlight-row="
        selectAssetClassifyTypeInfo.data[selectAssetClassifyTypeInfo.key]
          .highlightRow
      "
      @callback="callBackSelectClassifyType"
    />
    <SelectFiscalPeriod
      v-if="selectFiscalPeriodInfo.visible"
      v-model:show-dialog="selectFiscalPeriodInfo.visible"
      :api="selectFiscalPeriodInfo.api"
      :query="props.query"
      :save-empty="true"
      :checked-list="
        selectFiscalPeriodInfo.data[selectFiscalPeriodInfo.key].checkBox
          ? selectFiscalPeriodInfo.data[selectFiscalPeriodInfo.key].checkedList
          : []
      "
      :check-box="
        selectFiscalPeriodInfo.data[selectFiscalPeriodInfo.key].checkBox
      "
      :highlight-row="
        selectFiscalPeriodInfo.data[selectFiscalPeriodInfo.key].highlightRow
      "
      @callback="callBackSelectFiscalPeriod"
    />
    <SelectPatrolRoute
      v-if="selectPatrolRouteInfo.visible"
      v-model:show-dialog="selectPatrolRouteInfo.visible"
      :save-empty="true"
      :checked-list="
        selectPatrolRouteInfo.data[selectPatrolRouteInfo.key].checkBox
          ? selectPatrolRouteInfo.data[selectPatrolRouteInfo.key].checkedList
          : []
      "
      :check-box="
        selectPatrolRouteInfo.data[selectPatrolRouteInfo.key].checkBox
      "
      :highlight-row="
        selectPatrolRouteInfo.data[selectPatrolRouteInfo.key].highlightRow
      "
      @callback="callBackPatrolRouteInfo"
    />
    <SelectMaintenance
      v-if="selectMaintenanceInfo.visible"
      v-model:show-dialog="selectMaintenanceInfo.visible"
      :save-empty="true"
      :checked-list="
        selectMaintenanceInfo.data[selectMaintenanceInfo.key].checkBox
          ? selectMaintenanceInfo.data[selectMaintenanceInfo.key].checkedList
          : []
      "
      :check-box="
        selectMaintenanceInfo.data[selectMaintenanceInfo.key].checkBox
      "
      :highlight-row="
        selectMaintenanceInfo.data[selectMaintenanceInfo.key].highlightRow
      "
      @callback="callBackMaintenanceInfo"
    />
    <!-- 维修人员 -->
    <SelectRepairUser
      v-if="selectRepairUserInfo.visible"
      v-model:showDialog="selectRepairUserInfo.visible"
      :checked-list="
        selectRepairUserInfo.data[selectRepairUserInfo.key].checkBox
          ? selectRepairUserInfo.data[selectRepairUserInfo.key].checkedList
          : []
      "
      :check-box="selectRepairUserInfo.data[selectRepairUserInfo.key].checkBox"
      :highlight-row="
        selectRepairUserInfo.data[selectRepairUserInfo.key].highlightRow
      "
      :saveEmpty="true"
      @callback="selectRepairUserCallBack"
    />
    <SelectMaintenanceUser
      :title="selectMaintenanceUserInfo.title"
      v-if="selectMaintenanceUserInfo.visible"
      v-model:showDialog="selectMaintenanceUserInfo.visible"
      :checked-list="
        selectMaintenanceUserInfo.data[selectMaintenanceUserInfo.key].checkBox
          ? selectMaintenanceUserInfo.data[selectMaintenanceUserInfo.key]
              .checkedList
          : []
      "
      :check-box="
        selectMaintenanceUserInfo.data[selectMaintenanceUserInfo.key].checkBox
      "
      :highlight-row="
        selectMaintenanceUserInfo.data[selectMaintenanceUserInfo.key]
          .highlightRow
      "
      :saveEmpty="true"
      @callback="selectMaintenanceUserCallBack"
    />
    <SelectCargoSpace
      v-if="selectCargoSpaceInfo.visible"
      v-model:showDialog="selectCargoSpaceInfo.visible"
      :checked-list="
        selectCargoSpaceInfo.data[selectCargoSpaceInfo.key].checkBox
          ? selectCargoSpaceInfo.data[selectCargoSpaceInfo.key].checkedList
          : []
      "
      :check-box="selectCargoSpaceInfo.data[selectCargoSpaceInfo.key].checkBox"
      :highlight-row="
        selectCargoSpaceInfo.data[selectCargoSpaceInfo.key].highlightRow
      "
      :saveEmpty="true"
      @callback="selectCargoSpaceCallBack"
    />
    <SelectProductClassification
      v-if="productClassificationInfo.visible"
      v-model:showDialog="productClassificationInfo.visible"
      :checked-list="
        productClassificationInfo.data[productClassificationInfo.key].checkBox
          ? productClassificationInfo.data[productClassificationInfo.key]
              .checkedList
          : []
      "
      :check-box="
        productClassificationInfo.data[productClassificationInfo.key].checkBox
      "
      :highlight-row="
        productClassificationInfo.data[productClassificationInfo.key]
          .highlightRow
      "
      :saveEmpty="true"
      @callback="callBackProductClass"
    />
  </div>
</template>
<script setup name="AdvancedSearch">
/*
 *componentType: string input输入框
 *componentType: number 数字输入框
 * componentType: price 价格
 * componentType: date 日期输入框
 * componentType: dateTime 日期时间输入框
 * componentType: selectModel 字典输入框
 * codeType: 字典
 * asValue: value映射
 */
import { getRrgUserList } from '@/api/base.js'
import {
  useStatusPage,
  getClassificationPage,
  getCategoryPage,
  getClassifyPage,
} from '@/api/asset'
import { getDeptPage, getCoreFiscalPeriodPage } from '@/api/core.js'
import pinyin from 'js-pinyin'
const PageDialog = defineAsyncComponent(() =>
  import('@/components/PageDialog/index')
)
const SelectModel = defineAsyncComponent(() =>
  import('@/components/SelectModel/index')
)
const SelectUsers = defineAsyncComponent(() =>
  import('@/components/SelectUsers/index')
)
const SelectDept = defineAsyncComponent(() =>
  import('@/components/SelectDept/index')
)
const SlipSelect = defineAsyncComponent(() =>
  import('@/components/SlipSelect/index')
)
const NewSelectProduct = defineAsyncComponent(() =>
  import('@/components/NewSelectProduct/index')
)
const SelectUseStatus = defineAsyncComponent(() =>
  import('@/components/SelectUseStatus/index')
)
const SelectSettingClassification = defineAsyncComponent(() =>
  import('@/components/SelectSettingClassification/index')
)
const SelectSettingCategory = defineAsyncComponent(() =>
  import('@/components/SelectSettingCategory/index')
)
const SelectFiscalPeriod = defineAsyncComponent(() =>
  import('@/components/SelectFiscalPeriod/index')
)
const SelectPatrolRoute = defineAsyncComponent(() =>
  import('@/components/SelectPatrolRoute/index')
)
const SelectMaintenance = defineAsyncComponent(() =>
  import('@/components/SelectMaintenance/index')
)
const SelectRepairUser = defineAsyncComponent(() =>
  import('@/components/SelectUsers/selectMaintenanceUsers')
)
const SelectMaintenanceUser = defineAsyncComponent(() =>
  import('@/components/SelectUsers/selectMaintenanceUsers')
)
const SelectCargoSpace = defineAsyncComponent(() =>
  import('@/components/SelectCargoSpace/index')
)
const SelectAssetClassify = defineAsyncComponent(() =>
  import('@/components/SelectAssetClassify/index')
)
const SelectProductClassification = defineAsyncComponent(() =>
  import('@/components/SelectProductClassification/index')
)
const emits = defineEmits()
const { proxy } = getCurrentInstance()
const props = defineProps({
  visible: {
    type: Boolean,
  },
  fieldList: {
    type: Array,
    default: function () {
      return []
    },
  },
  formData: {
    type: Object,
    default: function () {
      return {}
    },
  },
  query: {
    type: Object,
  },
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emits('update:visible', newValue) // 更新父组件shows
  },
})

const dialogInfo = ref({
  title: '高级查询',
  width: '800px',
  btLoading: false,
  btList: [
    { label: '关闭', event: handleClose, show: true },
    {
      label: '保存',
      type: 'primary',
      disabled: false,
      event: save,
      show: true,
    },
  ],
})
const queryCategoryOption = ref([
  { label: 'AND（所有条件都要求匹配）', value: 'AND' },
  { label: 'OR（条件中的任意一个匹配）', value: 'OR' },
])
const newFiledList = ref([])
const copyNewFiledList = ref([])
const queryCategory = ref('AND')
const formInfo = ref([])
const systemConfig = ref(proxy.$store.state.permission.systemConfig)
const userInfo = ref({
  visible: false,
  api: getRrgUserList,
  row: {},
  data: {},
  key: '',
})
const selectUseStatusInfo = ref({
  visible: false,
  saveEmpty: true,
  api: useStatusPage,
  row: {},
  data: {},
  key: '',
})
const selectDeptInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getDeptPage,
  row: {},
  data: {},
  key: '',
})
const selectPatrolRouteInfo = ref({
  visible: false,
  saveEmpty: true,
  row: {},
  data: {},
  key: '',
})
const selectDeviceTypeInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getClassificationPage,
  row: {},
  data: {},
  key: '',
})
const selectFinanceTypeInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getCategoryPage,
  row: {},
  data: {},
  key: '',
})
const selectAssetClassifyTypeInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getClassifyPage,
  row: {},
  data: {},
  key: '',
})
const selectFiscalPeriodInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getCoreFiscalPeriodPage,
  row: {},
  data: {},
  key: '',
})
const selectMaintenanceInfo = ref({
  visible: false,
  saveEmpty: true,
  row: {},
  data: {},
  key: '',
})
const selectRepairUserInfo = ref({
  visible: false,
  saveEmpty: true,
  row: {},
  data: {},
  key: '',
})
const selectMaintenanceUserInfo = ref({
  title: '请选择维修人员',
  visible: false,
  saveEmpty: true,
  row: {},
  data: {},
  key: '',
})
const selectCargoSpaceInfo = ref({
  visible: false,
  saveEmpty: true,
  row: {},
  data: {},
  key: '',
})
const productClassificationInfo = ref({
  visible: false,
  saveEmpty: true,
  row: {},
  data: {},
  key: '',
})
const productInfo = ref({
  visible: false,
  row: {},
  data: {},
  key: '',
  tableKey: 'searchByProdectId-com.slip.spd.entity.vo.core.CoreProductVONew',
  query: {
    queryMap: {
      status: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: 1,
      },
      type: {
        asTbName: 'core_product_new',
        columnName: 'type',
        queryResource: 0,
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: 0,
      },
    },
  },
})
const isMultiple = ref('noMultiple')

setData()
function setData() {
  let fieldList = proxy.$fn.deepClone(props.fieldList)
  newFiledList.value = fieldList.filter((item) => {
    if (item.hidden === false) {
      item.value = item.asValue ? item.asValue : item.value
      return item
    }
  })
  copyNewFiledList.value = proxy.$fn.deepClone(newFiledList.value)
  if (Object.keys(props.formData).length) {
    queryCategory.value = props.formData.queryCategory
      ? props.formData.queryCategory
      : 'AND'
    formInfo.value = props.formData.formInfo.length
      ? props.formData.formInfo
      : [{ queryType: '', asName: '', value: '', label: '' }]
    productInfo.value = props.formData.productInfo
    userInfo.value = props.formData.userInfo
  } else {
    formInfo.value = [{ queryType: '', asName: '', value: '', label: '' }]
  }
  console.log(formInfo.value, 'formInfo.value')
}
function visibleChange(val) {
  if (!val) {
    newFiledList.value = proxy.$fn.deepClone(copyNewFiledList.value)
  }
}
function filterMethod(value) {
  //	自定义搜索方法
  if (value) {
    let result = []
    copyNewFiledList.value.forEach((item) => {
      pinyin.setOptions({ checkPolyphone: false, charCase: 1 })
      const resultEng = pinyin.getCamelChars(item.label).toUpperCase()
      const matchResult =
        item.label.indexOf(value) !== -1 ||
        resultEng.indexOf(value.toUpperCase()) !== -1
      // let matchResult = PinYinMatch.match(item.label, value)
      if (matchResult) {
        result.push(item)
      }
    })
    newFiledList.value = result
  } else {
    newFiledList.value = copyNewFiledList.value
  }
}
function checkUser(row, index) {
  userInfo.value.visible = true
  userInfo.value.key = row.asName + index
  userInfo.value.row = row
  if (!userInfo.value.data[row.asName + index]) {
    userInfo.value.data[row.asName + index] = proxy.$fn.deepClone(row)
  }
}
function checkUserStatus(row, index) {
  selectUseStatusInfo.value.visible = true
  selectUseStatusInfo.value.key = row.asName + index
  selectUseStatusInfo.value.row = row
  if (!selectUseStatusInfo.value.data[row.asName + index]) {
    selectUseStatusInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkDept(row, index) {
  selectDeptInfo.value.visible = true
  selectDeptInfo.value.key = row.asName + index
  selectDeptInfo.value.row = row
  if (!selectDeptInfo.value.data[row.asName + index]) {
    selectDeptInfo.value.data[row.asName + index] = proxy.$fn.deepClone(row)
  }
}
function checkSelectDevice(row, index) {
  selectDeviceTypeInfo.value.visible = true
  selectDeviceTypeInfo.value.key = row.asName + index
  selectDeviceTypeInfo.value.row = row
  if (!selectDeviceTypeInfo.value.data[row.asName + index]) {
    selectDeviceTypeInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkSelectFinance(row, index) {
  selectFinanceTypeInfo.value.visible = true
  selectFinanceTypeInfo.value.key = row.asName + index
  selectFinanceTypeInfo.value.row = row
  if (!selectFinanceTypeInfo.value.data[row.asName + index]) {
    selectFinanceTypeInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkSelectClassify(row, index) {
  selectAssetClassifyTypeInfo.value.visible = true
  selectAssetClassifyTypeInfo.value.key = row.asName + index
  selectAssetClassifyTypeInfo.value.row = row
  if (!selectAssetClassifyTypeInfo.value.data[row.asName + index]) {
    selectAssetClassifyTypeInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkFiscalPeriod(row, index) {
  selectFiscalPeriodInfo.value.visible = true
  selectFiscalPeriodInfo.value.key = row.asName + index
  selectFiscalPeriodInfo.value.row = row
  if (!selectFiscalPeriodInfo.value.data[row.asName + index]) {
    selectFiscalPeriodInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkPatrolRoute(row, index) {
  selectPatrolRouteInfo.value.visible = true
  selectPatrolRouteInfo.value.key = row.asName + index
  selectPatrolRouteInfo.value.row = row
  if (!selectPatrolRouteInfo.value.data[row.asName + index]) {
    selectPatrolRouteInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkMaintenance(row, index) {
  selectMaintenanceInfo.value.visible = true
  selectMaintenanceInfo.value.key = row.asName + index
  selectMaintenanceInfo.value.row = row
  if (!selectMaintenanceInfo.value.data[row.asName + index]) {
    selectMaintenanceInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkRepairUser(row, index) {
  selectRepairUserInfo.value.visible = true
  selectRepairUserInfo.value.key = row.asName + index
  selectRepairUserInfo.value.row = row
  if (!selectRepairUserInfo.value.data[row.asName + index]) {
    selectRepairUserInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkMaintenanceUser(row, index) {
  selectMaintenanceUserInfo.value.visible = true
  selectMaintenanceUserInfo.value.key = row.asName + index
  selectMaintenanceUserInfo.value.row = row
  if (!selectMaintenanceUserInfo.value.data[row.asName + index]) {
    selectMaintenanceUserInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkshelfNo(row, index) {
  selectCargoSpaceInfo.value.visible = true
  selectCargoSpaceInfo.value.key = row.asName + index
  selectCargoSpaceInfo.value.row = row
  if (!selectCargoSpaceInfo.value.data[row.asName + index]) {
    selectCargoSpaceInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function checkProductClass(row, index) {
  productClassificationInfo.value.visible = true
  productClassificationInfo.value.key = row.asName + index
  productClassificationInfo.value.row = row
  if (!productClassificationInfo.value.data[row.asName + index]) {
    productClassificationInfo.value.data[row.asName + index] =
      proxy.$fn.deepClone(row)
  }
}
function callBackUser(row) {
  let key = userInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      userInfo.value.data[key].checkedList = ids
    }
    userInfo.value.row.value = ids.toString()
    userInfo.value.row.userName = row.map((item) => item.name).toString()
  } else {
    userInfo.value.row.value = ''
    userInfo.value.row.userName = ''
    userInfo.value.data[key].checkedList = []
  }
  console.log(userInfo.value.data)
}
function callBackUserStatus(row) {
  let key = selectUseStatusInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectUseStatusInfo.value.data[key].checkedList = ids
    }
    selectUseStatusInfo.value.row.value = ids.toString()
    selectUseStatusInfo.value.row.userStatusValue = row
      .map((item) => item.name)
      .toString()
  } else {
    selectUseStatusInfo.value.row.value = ''
    selectUseStatusInfo.value.row.userStatusValue = ''
    selectUseStatusInfo.value.data[key].checkedList = []
  }
}
function callBackDept(row) {
  let key = selectDeptInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectDeptInfo.value.data[key].checkedList = ids
    }
    selectDeptInfo.value.row.value = ids.toString()
    selectDeptInfo.value.row.deptName = row.map((item) => item.name).toString()
  } else {
    selectDeptInfo.value.row.value = ''
    selectDeptInfo.value.row.deptName = ''
    selectDeptInfo.value.data[key].checkedList = []
  }
}
function callBackselectDeviceType(row) {
  let key = selectDeviceTypeInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectDeviceTypeInfo.value.data[key].checkedList = ids
    }
    selectDeviceTypeInfo.value.row.value = ids.toString()
    selectDeviceTypeInfo.value.row.selectDevice = row
      .map((item) => item.name)
      .toString()
  } else {
    selectDeviceTypeInfo.value.row.value = ''
    selectDeviceTypeInfo.value.row.selectDevice = ''
    selectDeviceTypeInfo.value.data[key].checkedList = []
  }
}
function callBackSelectFinanceType(row) {
  let key = selectFinanceTypeInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectFinanceTypeInfo.value.data[key].checkedList = ids
    }
    selectFinanceTypeInfo.value.row.value = ids.toString()
    selectFinanceTypeInfo.value.row.selectFinance = row
      .map((item) => item.name)
      .toString()
  } else {
    selectFinanceTypeInfo.value.row.value = ''
    selectFinanceTypeInfo.value.row.selectFinance = ''
    selectFinanceTypeInfo.value.data[key].checkedList = []
  }
}
function callBackSelectClassifyType(row) {
  let key = selectAssetClassifyTypeInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectAssetClassifyTypeInfo.value.data[key].checkedList = ids
    }
    selectAssetClassifyTypeInfo.value.row.value = ids.toString()
    selectAssetClassifyTypeInfo.value.row.selectClassify = row
      .map((item) => item.name)
      .toString()
  } else {
    selectAssetClassifyTypeInfo.value.row.value = ''
    selectAssetClassifyTypeInfo.value.row.selectClassify = ''
    selectAssetClassifyTypeInfo.value.data[key].checkedList = []
  }
}
function callBackSelectFiscalPeriod(row) {
  let key = selectFiscalPeriodInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let names = row.map((item) => item.name)
    if (type === '[object Array]') {
      selectFiscalPeriodInfo.value.data[key].checkedList = names
    }
    selectFiscalPeriodInfo.value.row.value = names.toString()
    selectFiscalPeriodInfo.value.row.fiscalPeriod = row
      .map((item) => item.name)
      .toString()
  } else {
    selectFiscalPeriodInfo.value.row.value = ''
    selectFiscalPeriodInfo.value.row.fiscalPeriod = ''
    selectFiscalPeriodInfo.value.data[key].checkedList = []
  }
}
function callBackPatrolRouteInfo(row) {
  let key = selectPatrolRouteInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectPatrolRouteInfo.value.data[key].checkedList = ids
    }
    selectPatrolRouteInfo.value.row.value = ids.toString()
    selectPatrolRouteInfo.value.row.patrolRoute = row
      .map((item) => item.routeName)
      .toString()
  } else {
    selectPatrolRouteInfo.value.row.value = ''
    selectPatrolRouteInfo.value.row.patrolRoute = ''
    selectPatrolRouteInfo.value.data[key].checkedList = []
  }
}
function callBackMaintenanceInfo(row) {
  let key = selectMaintenanceInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.maintenanceId)
    if (type === '[object Array]') {
      selectMaintenanceInfo.value.data[key].checkedList = ids
    }
    selectMaintenanceInfo.value.row.value = ids.toString()
    selectMaintenanceInfo.value.row.maintenance = row
      .map((item) => item.maintenanceName)
      .toString()
  } else {
    selectMaintenanceInfo.value.row.value = ''
    selectMaintenanceInfo.value.row.maintenance = ''
    selectMaintenanceInfo.value.data[key].checkedList = []
  }
}
function selectRepairUserCallBack(row) {
  let key = selectRepairUserInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectRepairUserInfo.value.data[key].checkedList = ids
    }
    selectRepairUserInfo.value.row.value = ids.toString()
    selectRepairUserInfo.value.row.name = row
      .map((item) => item.name)
      .toString()
  } else {
    selectRepairUserInfo.value.row.value = ''
    selectRepairUserInfo.value.row.name = ''
    selectRepairUserInfo.value.data[key].checkedList = []
  }
}
function selectMaintenanceUserCallBack(row) {
  let key = selectMaintenanceUserInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectMaintenanceUserInfo.value.data[key].checkedList = ids
    }
    selectMaintenanceUserInfo.value.row.value = ids.toString()
    selectMaintenanceUserInfo.value.row.name = row
      .map((item) => item.name)
      .toString()
  } else {
    selectMaintenanceUserInfo.value.row.value = ''
    selectMaintenanceUserInfo.value.row.name = ''
    selectMaintenanceUserInfo.value.data[key].checkedList = []
  }
}
function selectCargoSpaceCallBack(row) {
  let key = selectCargoSpaceInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      selectCargoSpaceInfo.value.data[key].checkedList = ids
    }
    selectCargoSpaceInfo.value.row.value = ids.toString()
    selectCargoSpaceInfo.value.row.locationNo = row
      .map((item) => item.locationNo)
      .toString()
  } else {
    selectCargoSpaceInfo.value.row.value = ''
    selectCargoSpaceInfo.value.row.locationNo = ''
    selectCargoSpaceInfo.value.data[key].checkedList = []
  }
}
function timeChange(val, row) {
  if (val && val.length) {
    row.value = val[0] + ',' + val[1]
  } else {
    row.value = null
  }
}
function checkProduct(row, index) {
  productInfo.value.visible = true
  productInfo.value.key = row.asName + index
  productInfo.value.row = row
  if (!productInfo.value.data[row.asName + index]) {
    productInfo.value.data[row.asName + index] = proxy.$fn.deepClone(row)
  }
  console.log(productInfo.value)
}
function selectProduct(row) {
  let key = productInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      productInfo.value.data[key].checkedList = ids
    }
    productInfo.value.row.value = ids.toString()
    productInfo.value.row.commonName = row
      .map((item) => item.commonName)
      .toString()
  } else {
    productInfo.value.row.value = ''
    productInfo.value.row.commonName = ''
    productInfo.value.data[key].checkedList = []
  }
}
function callBackProductClass(row) {
  let key = productClassificationInfo.value.key
  let type = Object.prototype.toString.call(row)
  row =
    type === '[object Object]' ? [row] : type === '[object Array]' ? row : []
  if (row.length) {
    let ids = row.map((item) => item.id)
    if (type === '[object Array]') {
      productClassificationInfo.value.data[key].checkedList = ids
    }
    productClassificationInfo.value.row.value = ids.toString()
    productClassificationInfo.value.row.name = row
      .map((item) => item.name)
      .toString()
  } else {
    productClassificationInfo.value.row.value = ''
    productClassificationInfo.value.row.name = ''
    productClassificationInfo.value.data[key].checkedList = []
  }
}
function save() {
  let _formInfo = formInfo.value
  let arr = []
  _formInfo.forEach((item) => {
    if (item.asName) {
      arr.push({
        queryType: item.queryType,
        value: item.value,
        fieldName: item.asName,
        queryCategory: queryCategory.value,
      })
    }
  })
  emits('callback', {
    queryDtoList: arr,
    data: {
      formInfo: _formInfo,
      productInfo: productInfo.value,
      userInfo: userInfo.value,
      queryCategory: queryCategory.value,
    },
  })
  showDialog.value = false
}
function handleClose() {
  showDialog.value = false
}
function changeQueryType(val, row, index) {
  let key = row.asName + index
  if (
    val === 'IN' ||
    val === 'NOT_IN' ||
    val === 'BETWEEN' ||
    val === 'NOT_BETWEEN'
  ) {
    row.value = ''
    if (
      row.componentType === 'select-model' ||
      row.componentType === 'slip-select'
    ) {
      isMultiple.value = 'multiple'
      row.multiple = true
    } else if (row.fieldType === 'LocalDateTime') {
      row.componentType = 'datetimerange'
    } else if (row.fieldType === 'LocalDate') {
      row.componentType = 'daterange'
    } else if (row.componentType === 'select-user') {
      userInfo.value.data[key].checkBox = true
      userInfo.value.data[key].highlightRow = false
      row.userName = ''
      userInfo.value.data[key].checkedList = []
      userInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-use-status') {
      selectUseStatusInfo.value.data[key].checkBox = true
      selectUseStatusInfo.value.data[key].highlightRow = false
      row.userStatusValue = ''
      selectUseStatusInfo.value.data[key].checkedList = []
      selectUseStatusInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-dept') {
      selectDeptInfo.value.data[key].checkBox = true
      selectDeptInfo.value.data[key].highlightRow = false
      row.userStatusValue = ''
      selectDeptInfo.value.data[key].checkedList = []
      selectDeptInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-device-type') {
      selectDeviceTypeInfo.value.data[key].checkBox = true
      selectDeviceTypeInfo.value.data[key].highlightRow = false
      row.selectDevice = ''
      selectDeviceTypeInfo.value.data[key].checkedList = []
      selectDeviceTypeInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-finance-type') {
      selectFinanceTypeInfo.value.data[key].checkBox = true
      selectFinanceTypeInfo.value.data[key].highlightRow = false
      row.selectFinance = ''
      selectFinanceTypeInfo.value.data[key].checkedList = []
      selectFinanceTypeInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-asset-classify-type') {
      selectAssetClassifyTypeInfo.value.data[key].checkBox = true
      selectAssetClassifyTypeInfo.value.data[key].highlightRow = false
      row.selectFinance = ''
      selectAssetClassifyTypeInfo.value.data[key].checkedList = []
      selectAssetClassifyTypeInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-fiscal-period') {
      selectFiscalPeriodInfo.value.data[key].checkBox = true
      selectFiscalPeriodInfo.value.data[key].highlightRow = false
      row.fiscalPeriod = ''
      selectFiscalPeriodInfo.value.data[key].checkedList = []
      selectFiscalPeriodInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-product') {
      productInfo.value.data[key].checkBox = true
      productInfo.value.data[key].highlightRow = false
      row.commonName = ''
      productInfo.value.data[key].checkedList = []
      productInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-patrol-route') {
      selectPatrolRouteInfo.value.data[key].checkBox = true
      selectPatrolRouteInfo.value.data[key].highlightRow = false
      row.patrolRoute = ''
      selectPatrolRouteInfo.value.data[key].checkedList = []
      selectPatrolRouteInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-maintenance') {
      selectMaintenanceInfo.value.data[key].checkBox = true
      selectMaintenanceInfo.value.data[key].highlightRow = false
      row.maintenance = ''
      selectMaintenanceInfo.value.data[key].checkedList = []
      selectMaintenanceInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-repair-user') {
      selectRepairUserInfo.value.data[key].checkBox = true
      selectRepairUserInfo.value.data[key].highlightRow = false
      row.name = ''
      selectRepairUserInfo.value.data[key].checkedList = []
      selectRepairUserInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-maintenance-user') {
      selectMaintenanceUserInfo.value.data[key].checkBox = true
      selectMaintenanceUserInfo.value.data[key].highlightRow = false
      row.name = ''
      selectMaintenanceUserInfo.value.data[key].checkedList = []
      selectMaintenanceUserInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-shelf-no') {
      selectCargoSpaceInfo.value.data[key].checkBox = true
      selectCargoSpaceInfo.value.data[key].highlightRow = false
      row.locationNo = ''
      selectCargoSpaceInfo.value.data[key].checkedList = []
      selectCargoSpaceInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-product-class') {
      productClassificationInfo.value.data[key].checkBox = true
      productClassificationInfo.value.data[key].highlightRow = false
      row.name = ''
      productClassificationInfo.value.data[key].checkedList = []
      productClassificationInfo.value.data[key].queryType = val
    }
  } else {
    row.value = ''
    if (
      row.componentType === 'select-model' ||
      row.componentType === 'slip-select'
    ) {
      isMultiple.value = 'noMultiple'
      row.multiple = false
    } else if (row.fieldType === 'LocalDateTime') {
      row.componentType = 'dateTime'
      row.timeInfo = []
    } else if (row.fieldType === 'LocalDate') {
      row.componentType = 'date'
      row.timeInfo = []
    } else if (row.fieldType === 'LocalTime') {
      row.componentType = 'time'
      row.timeInfo = []
    } else if (row.componentType === 'select-user') {
      userInfo.value.data[key].checkBox = false
      userInfo.value.data[key].highlightRow = true
      row.userName = ''
      userInfo.value.data[key].checkedList = []
      userInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-product') {
      productInfo.value.data[key].checkBox = false
      productInfo.value.data[key].highlightRow = true
      row.commonName = ''
      productInfo.value.data[key].checkedList = []
      productInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-use-status') {
      selectUseStatusInfo.value.data[key].checkBox = false
      selectUseStatusInfo.value.data[key].highlightRow = true
      row.userStatusValue = ''
      selectUseStatusInfo.value.data[key].checkedList = []
      selectUseStatusInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-dept') {
      selectDeptInfo.value.data[key].checkBox = false
      selectDeptInfo.value.data[key].highlightRow = true
      row.userStatusValue = ''
      selectDeptInfo.value.data[key].checkedList = []
      selectDeptInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-device-type') {
      selectDeviceTypeInfo.value.data[key].checkBox = false
      selectDeviceTypeInfo.value.data[key].highlightRow = true
      row.selectDevice = ''
      selectDeviceTypeInfo.value.data[key].checkedList = []
      selectDeviceTypeInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-finance-type') {
      selectFinanceTypeInfo.value.data[key].checkBox = false
      selectFinanceTypeInfo.value.data[key].highlightRow = true
      row.selectFinance = ''
      selectFinanceTypeInfo.value.data[key].checkedList = []
      selectFinanceTypeInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-asset-classify-type') {
      selectAssetClassifyTypeInfo.value.data[key].checkBox = false
      selectAssetClassifyTypeInfo.value.data[key].highlightRow = true
      row.selectClassify = ''
      selectAssetClassifyTypeInfo.value.data[key].checkedList = []
      selectAssetClassifyTypeInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-fiscal-period') {
      selectFiscalPeriodInfo.value.data[key].checkBox = false
      selectFiscalPeriodInfo.value.data[key].highlightRow = true
      row.fiscalPeriod = ''
      selectFiscalPeriodInfo.value.data[key].checkedList = []
      selectFiscalPeriodInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-patrol-route') {
      selectPatrolRouteInfo.value.data[key].checkBox = false
      selectPatrolRouteInfo.value.data[key].highlightRow = true
      row.patrolRoute = ''
      selectPatrolRouteInfo.value.data[key].checkedList = []
      selectPatrolRouteInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-maintenance') {
      selectMaintenanceInfo.value.data[key].checkBox = false
      selectMaintenanceInfo.value.data[key].highlightRow = true
      row.maintenance = ''
      selectMaintenanceInfo.value.data[key].checkedList = []
      selectMaintenanceInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-repair-user') {
      selectRepairUserInfo.value.data[key].checkBox = false
      selectRepairUserInfo.value.data[key].highlightRow = true
      row.name = ''
      selectRepairUserInfo.value.data[key].checkedList = []
      selectRepairUserInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-maintenance-user') {
      selectMaintenanceUserInfo.value.data[key].checkBox = false
      selectMaintenanceUserInfo.value.data[key].highlightRow = true
      row.name = ''
      selectMaintenanceUserInfo.value.data[key].checkedList = []
      selectMaintenanceUserInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-shelf-no') {
      selectCargoSpaceInfo.value.data[key].checkBox = false
      selectCargoSpaceInfo.value.data[key].highlightRow = true
      row.locationNo = ''
      selectCargoSpaceInfo.value.data[key].checkedList = []
      selectCargoSpaceInfo.value.data[key].queryType = val
    } else if (row.componentType === 'select-product-class') {
      productClassificationInfo.value.data[key].checkBox = false
      productClassificationInfo.value.data[key].highlightRow = true
      row.name = ''
      productClassificationInfo.value.data[key].checkedList = []
      productClassificationInfo.value.data[key].queryType = val
    }
  }
}
function changeFiled(e, num) {
  let row = newFiledList.value.filter(
    (item) => e === (item.asValue ? item.asValue : item.value)
  )
  if (row.length) {
    formInfo.value.forEach((item, index) => {
      let isMultiple =
        item.queryType === 'IN' ||
        item.queryType === 'NOT_IN' ||
        item.queryType === 'BETWEEN' ||
        item.queryType === 'NOT_BETWEEN'
      if (item.asName === e && index === num) {
        item.componentType = row[0].componentType
        item.value = ''
        delete item.timeInfo
        delete item.checkBox
        delete item.highlightRow
        delete item.fieldType
        delete item.multiple
        if (row[0].componentType === 'select-model') {
          item.code = row[0].code ? row[0].code : ''
          item.multiple = isMultiple
          item.clearType = true
        } else {
          item.clearType = false
        }
        if (row[0].componentType === 'select-user') {
          item.userName = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (userInfo.value.data[e + num]) {
            userInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              userInfo.value.data[e + num].checkBox = true
              userInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              userInfo.value.data[e + num].checkBox = row[0].checkBox
              userInfo.value.data[e + num].highlightRow = row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-use-status') {
          item.userStatusValue = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectUseStatusInfo.value.data[e + num]) {
            selectUseStatusInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectUseStatusInfo.value.data[e + num].checkBox = true
              selectUseStatusInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectUseStatusInfo.value.data[e + num].checkBox = row[0].checkBox
              selectUseStatusInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-dept') {
          item.deptName = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectDeptInfo.value.data[e + num]) {
            selectDeptInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectDeptInfo.value.data[e + num].checkBox = true
              selectDeptInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectDeptInfo.value.data[e + num].checkBox = row[0].checkBox
              selectDeptInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-device-type') {
          item.selectDevice = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectDeviceTypeInfo.value.data[e + num]) {
            selectDeviceTypeInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectDeviceTypeInfo.value.data[e + num].checkBox = true
              selectDeviceTypeInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectDeviceTypeInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectDeviceTypeInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-finance-type') {
          item.selectFinance = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectFinanceTypeInfo.value.data[e + num]) {
            selectFinanceTypeInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectFinanceTypeInfo.value.data[e + num].checkBox = true
              selectFinanceTypeInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectFinanceTypeInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectFinanceTypeInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-asset-classify-type') {
          item.selectClassify = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectAssetClassifyTypeInfo.value.data[e + num]) {
            selectAssetClassifyTypeInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectAssetClassifyTypeInfo.value.data[e + num].checkBox = true
              selectAssetClassifyTypeInfo.value.data[
                e + num
              ].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectAssetClassifyTypeInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectAssetClassifyTypeInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-fiscal-period') {
          item.fiscalPeriod = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectFiscalPeriodInfo.value.data[e + num]) {
            selectFiscalPeriodInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectFiscalPeriodInfo.value.data[e + num].checkBox = true
              selectFiscalPeriodInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectFiscalPeriodInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectFiscalPeriodInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-patrol-route') {
          item.patrolRoute = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectPatrolRouteInfo.value.data[e + num]) {
            selectPatrolRouteInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectPatrolRouteInfo.value.data[e + num].checkBox = true
              selectPatrolRouteInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectPatrolRouteInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectPatrolRouteInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-repair-user') {
          item.name = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectRepairUserInfo.value.data[e + num]) {
            selectRepairUserInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectRepairUserInfo.value.data[e + num].checkBox = true
              selectRepairUserInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectRepairUserInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectRepairUserInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-maintenance-user') {
          item.name = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectMaintenanceUserInfo.value.data[e + num]) {
            selectMaintenanceUserInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectMaintenanceUserInfo.value.data[e + num].checkBox = true
              selectMaintenanceUserInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectMaintenanceUserInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectMaintenanceUserInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-shelf-no') {
          item.locationNo = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (selectCargoSpaceInfo.value.data[e + num]) {
            selectCargoSpaceInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              selectCargoSpaceInfo.value.data[e + num].checkBox = true
              selectCargoSpaceInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              selectCargoSpaceInfo.value.data[e + num].checkBox =
                row[0].checkBox
              selectCargoSpaceInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'select-product-class') {
          item.locationNo = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (productClassificationInfo.value.data[e + num]) {
            productClassificationInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              productClassificationInfo.value.data[e + num].checkBox = true
              productClassificationInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              productClassificationInfo.value.data[e + num].checkBox =
                row[0].checkBox
              productClassificationInfo.value.data[e + num].highlightRow =
                row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].fieldType === 'LocalDateTime') {
          item.fieldType = row[0].fieldType
          if (isMultiple) {
            item.componentType = 'datetimerange'
          }
        }
        if (row[0].fieldType === 'LocalDate') {
          item.fieldType = row[0].fieldType
          if (isMultiple) {
            item.componentType = 'daterange'
          }
        }
        if (row[0].componentType === 'select-product') {
          item.commonName = ''
          if (isMultiple) {
            item.checkBox = true
            item.highlightRow = false
          } else {
            item.checkBox = false
            item.highlightRow = true
          }
          if (productInfo.value.data[e + num]) {
            productInfo.value.data[e + num].checkedList = []
            if (isMultiple) {
              productInfo.value.data[e + num].checkBox = true
              productInfo.value.data[e + num].highlightRow = false
              item.checkBox = true
              item.highlightRow = false
            } else {
              productInfo.value.data[e + num].checkBox = row[0].checkBox
              productInfo.value.data[e + num].highlightRow = row[0].highlightRow
              item.checkBox = false
              item.highlightRow = true
            }
          }
        }
        if (row[0].componentType === 'slip-select') {
          item.clearable = row[0].clearable
          item.filterable = row[0].filterable
          item.keyField = row[0].keyField
          item.valueField = row[0].valueField
          item.multiple = isMultiple
          item.query = row[0].query
          item.api = row[0].api
          item.slipSelectRequest = true
          item.clearType = true
          if (proxy.$refs[`slipSelect${num}`]) {
            proxy.$nextTick(function () {
              proxy.$refs[`slipSelect${num}`][0].init()
            })
          }
        } else {
          item.slipSelectRequest = false
          item.clearType = false
        }
        item.label = row[0].label
      }
    })
  }
}
function addRow() {
  formInfo.value.push({ queryType: '', asName: '', value: '' })
}
function removeRow(index) {
  if (formInfo.value.length === 1) return
  formInfo.value.splice(index, 1)
}
</script>
<style scoped lang="scss">
.check-btn {
  font-size: 20px;
  padding: 2px 5px;
  box-sizing: border-box;
  vertical-align: middle;
  cursor: pointer;
}
.disabled-icon {
  color: #d1d1d1;
}
:deep(.advance-item) {
  padding-left: 5px;
  .el-form-item__content {
    display: flex;
    align-items: center;
  }
}
</style>
